#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <pthread.h>

long file_no[2];
void *thr_fn1(void *arg)
{
	sleep(1);
	printf("thread 1 returning\n");
	file_no[0] = 1333;
	return ((void *)1);
}

void *thr_fn2(void *arg)
{
	sleep(2);
	file_no[1] = 1222;
	printf("thread 2 returning\n");
	pthread_exit((void *)2);
}

int 
main(void)
{
	int err;
	pthread_t tid1, tid2;
	void *tret;

	err = pthread_create(&tid1, NULL, thr_fn1, NULL);
	err = pthread_create(&tid2, NULL, thr_fn2, NULL);

	err = pthread_join(tid1, &tret);
	printf("thread 1 return code %d\n", (int)tret);
	
	err = pthread_join(tid2, &tret);
	printf("thread 2 return code %d\n", (int)tret);

	printf("%d\n", file_no[0] + file_no[1]);
	exit(0);

}

